<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>yili的个人小站</title><meta name="author" content="yili"><meta name="copyright" content="yili"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="身骑白马">
<meta property="og:type" content="website">
<meta property="og:title" content="yili的个人小站">
<meta property="og:url" content="https://yili979.gitee.io/blog/page/3/index.html">
<meta property="og:site_name" content="yili的个人小站">
<meta property="og:description" content="身骑白马">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/10/05/BKpC6sFEo5Dl7qA.jpg">
<meta property="article:author" content="yili">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/10/05/BKpC6sFEo5Dl7qA.jpg"><link rel="shortcut icon" href="/blog/img/favicon.ico"><link rel="canonical" href="https://yili979.gitee.io/blog/page/3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'yili的个人小站',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2022-03-08 20:42:16'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/blog/css/custom.css" media="defer" onload="this.media='all'"><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/10/05/BKpC6sFEo5Dl7qA.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">28</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">13</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('/blog/img/index.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">yili的个人小站</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">yili的个人小站</h1><div id="site-subtitle"><span id="subtitle"></span></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left_radius"><a href="/blog/2021/10/04/nosql/MongoDB%E7%9A%84CURD/" title="MongoDB的CURD">     <img class="post_bg" src="https://images.pexels.com/photos/844297/pexels-photo-844297.jpeg?auto=compress&amp;cs=tinysrgb&amp;dpr=2&amp;h=650&amp;w=940" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="MongoDB的CURD"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/nosql/MongoDB%E7%9A%84CURD/" title="MongoDB的CURD">MongoDB的CURD</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T15:48:28.000Z" title="发表于 2021-10-04 23:48:28">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/MongoDB/">MongoDB</a></span></div><div class="content">MongoDB的CURD:satellite:  本章较长，请耐心看完1.Insert Documents下面是插入单条数据，选择性的插入一个文档即可。
12345&gt; db.yili.insertOne( &#123; name:&quot;sue&quot;, age:26, status:&quot;pending&quot; &#125; )&#123;        &quot;acknowledged&quot; : true,        &quot;insertedId&quot; : ObjectId(&quot;61134b74b4249744caec54fd&quot;)&#125;

使用insertMany插入多行内容：
1234567db.collection.insertMany(   [ &lt;document 1&gt; , &lt;document 2&gt;, ... ],   &#123;      writeConcern: &lt;document&gt;,      ordered: &lt;boolean&gt;   &#125; ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/blog/2021/10/04/mysql/InnoDB%E4%BA%8B%E5%8A%A1/" title="InnoDB事务">     <img class="post_bg" src="https://i.loli.net/2021/10/04/7PWqmtGLMs3hign.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="InnoDB事务"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/mysql/InnoDB%E4%BA%8B%E5%8A%A1/" title="InnoDB事务">InnoDB事务</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T14:50:51.000Z" title="发表于 2021-10-04 22:50:51">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/Mysql/">Mysql</a></span></div><div class="content">数据库事务下面为本篇文章的大纲：

1.事务特性在事务中的特性可以简称为ACID特性，分别代表四个数据库事务所具有的特性。
实现事务必须要遵守 4 个特性，分别如下：

原子性（Atomicity）：一个事务作为一个不可分割的最小单元。一个事务中的所有操作，要么全部完成，要么全部不完成，不会结束在中间某个环节，而且事务在执行过程中发生错误，会被回滚到事务开始前的状态，就像这个事务从来没有执行过一样；
一致性（Consistency）：数据库的完整性不会因为事务的执行而受到破坏，数据库总是从一个一致性的状态转换到另一个一致性的状态。比如在转账事务中，必须保证双方的总额是不会发生改变的，也称之为逻辑一致性。
隔离性（Isolation）：一个事务在提交之前，对其他事务是不可见的，在一定情况下避免了脏读的发生。
持久性（Durability）：一旦事务进行提交之后，对数据的修改就是永久的，即便系统故障也不会丢失。


那么数据库是如何实现这四个特性的呢？


对于原子性（Atomicity）和一致性（Consistency），数据库可以通过底层的一个undo log机制来进行实现，主要是对事 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/blog/2021/10/04/java/NIO/" title="NIO">     <img class="post_bg" src="https://i.loli.net/2021/10/04/juhE1Cgk82ZpQHX.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="NIO"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/java/NIO/" title="NIO">NIO</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T11:13:20.000Z" title="发表于 2021-10-04 19:13:20">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/Java-NIO/">Java NIO</a></span></div><div class="content">NIO1.多路复用模型我们试想一下这样的现实场景:
一个餐厅同时有100位客人到店，当然到店后第一件要做的事情就是点菜。但是问题来了，餐厅老板为了节约人力成本目前只有一位大堂服务员拿着唯一的一本菜单等待客人进行服务。

那么最笨(但是最简单)的方法是(方法A)，无论有多少客人等待点餐，服务员都把仅有的一份菜单递给其中一位客人，然后站在客人身旁等待这个客人完成点菜过程。在记录客人点菜内容后，把点菜记录交给后堂厨师。然后是第二位客人。。。。然后是第三位客人。很明显，只有脑袋被门夹过的老板，才会这样设置服务流程。因为随后的80位客人，再等待超时后就会离店(还会给差评)。
于是还有一种办法(方法B)，老板马上新雇佣99名服务员，同时印制99本新的菜单。每一名服务员手持一本菜单负责一位客人(关键不只在于服务员，还在于菜单。因为没有菜单客人也无法点菜)。在客人点完菜后，记录点菜内容交给后堂厨师(当然为了更高效，后堂厨师最好也有100名)。这样每一位客人享受的就是VIP服务咯，当然客人不会走，但是人力成本可是一个大头哦(亏死你)。
另外一种办法(方法C)，就是改进点菜的方式，当客人到店后，自己申请一 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/blog/2021/10/04/java/Netty%E6%A2%B3%E7%90%86/" title="Netty梳理">     <img class="post_bg" src="https://i.loli.net/2021/10/04/O719aYEAueVQTsn.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Netty梳理"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/java/Netty%E6%A2%B3%E7%90%86/" title="Netty梳理">Netty梳理</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T11:06:01.000Z" title="发表于 2021-10-04 19:06:01">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/Java-NIO/">Java NIO</a></span></div><div class="content">NettyNetty在java中使用非常广泛，通过对Java NIO进行梳理得到的一个易于使用的IO类型框架。

1.引导存在两种类型的引导方式：一种用于客户端的是Bootstrap，另一种是用于服务端的ServerBootstrap。

ServerBootstrap存在两个EventLoopGroup，也就是在绑定这个引导时需要建立两个group，他们两个分别有着不同的作用，一个是监听作用，另一个是接受来自客户端的Channel。
2.ByteBuf优点：

可以被用户自定义的缓冲区类型扩展
通过内置的复合缓冲区类型实现了透明的零拷贝
容量可以按需增长
在读和写这两种模式之间切换不需要调用ByteBuffer的flip方法
读和写使用了不同的索引
支持方法的链式调用
支持引用计数
支持池化

ByteBuf 主要分为三种类型
Pooled 和 Unpooled，池化和非池化；

Heap 和 Direct，堆内存和直接内存；

Safe 和 Unsafe，安全和非安全。


池化和非池化： 池化就是用完就放回池子里面，比如我们所熟悉的数据库连接池。非池化就是每次使用都重新创建，使用 ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/blog/2021/10/04/pattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E8%A1%8C%E4%B8%BA%E5%9E%8B%E6%A8%A1%E5%BC%8F/" title="设计模式-行为型模式">     <img class="post_bg" src="https://i.loli.net/2021/10/04/HbJYwl6DFys9kcx.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="设计模式-行为型模式"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/pattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E8%A1%8C%E4%B8%BA%E5%9E%8B%E6%A8%A1%E5%BC%8F/" title="设计模式-行为型模式">设计模式-行为型模式</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T10:41:40.000Z" title="发表于 2021-10-04 18:41:40">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">java设计模式</a></span></div><div class="content">行为型模式
1.责任链模式责任链中存在多个类来处理请求，避免一个发送者只对应一个接收者，将这样的对象连城一条链，沿着这个链来进行传递，直到有一个对象处理。

链中的每个对象都有机会处理请求
链中的每个对象都有下一个处理对象的引用
链中的对象如果无法处理请求，则将请求传递给下一个对象


这就是servlet中对过滤器的实现方式，如果不满足条件可以直接跳过执行下一个过滤器，如果满足条件则在这个过程中进行过滤，比如对字符集的检查，如果字符集不满足条件，则抛出异常或者直接拦截向前端返回一个Error错误。在登陆验证和对字符集的过滤中经常看见。
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677public class ServeltHandler &#123;    public static void main(String[] args) &#123; ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/blog/2021/10/04/pattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E7%BB%93%E6%9E%84%E5%9E%8B%E6%A8%A1%E5%BC%8F/" title="设计模式-结构型模式">     <img class="post_bg" src="https://i.loli.net/2021/10/04/HbJYwl6DFys9kcx.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="设计模式-结构型模式"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/pattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E7%BB%93%E6%9E%84%E5%9E%8B%E6%A8%A1%E5%BC%8F/" title="设计模式-结构型模式">设计模式-结构型模式</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T10:41:03.000Z" title="发表于 2021-10-04 18:41:03">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">java设计模式</a></span></div><div class="content">结构型模式1.适配器模式（adapter）假如一个客户需要一个电视，但是现在的店里的国行电视都卖完了，但是店里还有卖剩下的欧版电视，所以需要一个电源适配器，将欧标的电源改为中国大陆所使用的电源。
1234567891011121314151617181920212223242526272829303132public class Adapter &#123;    public static void main(String[] args) &#123;        EuropeTV europeTV = new EuropeTV();        ChinaAdapter chinaAdapter = new ChinaAdapter(europeTV);        chinaAdapter.V220();    &#125;&#125;interface China&#123;    void V220();&#125;interface Europe&#123;    void V110();&#125;class EuropeTV implements Europe&# ...</div></div></div><div class="recent-post-item"><div class="post_cover left_radius"><a href="/blog/2021/10/04/pattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E5%88%9B%E5%BB%BA%E8%80%85%E6%A8%A1%E5%BC%8F/" title="设计模式-创建者模式">     <img class="post_bg" src="https://i.loli.net/2021/10/04/HbJYwl6DFys9kcx.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="设计模式-创建者模式"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/pattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E5%88%9B%E5%BB%BA%E8%80%85%E6%A8%A1%E5%BC%8F/" title="设计模式-创建者模式">设计模式-创建者模式</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T10:35:11.000Z" title="发表于 2021-10-04 18:35:11">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/java%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">java设计模式</a></span></div><div class="content">创建者模式1.单例模式单例模式就是保证一个类仅仅存在一个实例。如果存在多个实例，那么会对性能造成影响，并且多个实例在进行的过程中容易出现错误。
保证对象的唯一性：

不允许其它程序使用new
在本类中创建对象
定义一个公开方法返回这个对象


饿汉式

12345678910111213/** * 饿汉式写法 * 在类在加载的过程中就生成了一个实例对象 */public class SingletonHunger &#123;    private SingletonHunger()&#123;    &#125;    private static SingletonHunger singletonHunger = new SingletonHunger();    public SingletonHunger getInstance()&#123;        return singletonHunger;    &#125;&#125;


懒汉式

懒汉式就是在第一次使用实例对象的时候再对实例进行生成。
可以有效的对资源进行平均分配。
12345678910111213141 ...</div></div></div><div class="recent-post-item"><div class="post_cover right_radius"><a href="/blog/2021/10/04/java/Java%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B/" title="Java内存模型">     <img class="post_bg" src="https://i.loli.net/2021/10/06/nNuTKYH48X3mvLo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="Java内存模型"></a></div><div class="recent-post-info"><a class="article-title" href="/blog/2021/10/04/java/Java%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B/" title="Java内存模型">Java内存模型</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2021-10-04T10:21:19.000Z" title="发表于 2021-10-04 18:21:19">2021-10-04</time></span><span class="article-meta"><span class="article-meta__separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/blog/categories/java%E5%9F%BA%E7%A1%80/">java基础</a></span></div><div class="content">Jvm内存模型Java内存模型（Java Memory Model ,JMM）就是一种符合内存模型规范的，屏蔽了各种硬件和操作系统的访问差异的，保证了Java程序在各种平台下对内存的访问都能保证效果一致的机制及规范。
一、基础1.并发编程中的关键问题最重要的问题是：·线程之间如何进行通信以及线程之间如何进行同步的问题·
在共享内存的并发模型里，线程之间共享程序的公共状态，通过写-读内存中的公共 状态进行隐式通信。在消息传递的并发模型里，线程之间没有公共状态，线程之间必须 通过发送消息来显式进行通信。
在内存共享的模型中，同步是显式进行的。所以程序猿要将互斥的内容进行显式指定。而在消息传递的模型中，同步是隐式进行的。
2.重排序在执行程序时，编译器和处理器会对指令进行重新排序。主要分为以下的几种：

编译器优化的重排序：在不改变程序的执行语义时可以改变语句的执行顺序
指令级别的重排序：由于现在的处理器所采用的是多线程技术，可能会出现指令级并行技术对指令进行重叠排序
内存系统的重排序：由于处理器对缓存进行操作，可能会出现内存中的乱序


3.并发编程的分类现阶段的处理器大多都是多核处理器， ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/blog/page/2/#content-inner"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/blog/">1</a><a class="page-number" href="/blog/page/2/#content-inner">2</a><span class="page-number current">3</span></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/10/05/BKpC6sFEo5Dl7qA.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">yili</div><div class="author-info__description">身骑白马</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">28</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">13</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/qiuyuyin"><i class="fab fa-github"></i><span>github🍟</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">啦啦啦，写的不好还请见谅😉<div class="twopeople"><div class="twopeople"><div class="container"style="height:200px;"><canvas class="illo"width="800"height="800"style="max-width: 200px; max-height: 200px; touch-action: none; width: 640px; height: 640px;"></canvas></div><script src="js/twopeople1.js"></script><script src="js/zdog.dist.js"></script><script id="rendered-js"src="js/twopeople.js"></script><style>.twopeople{margin:0;align-items:center;justify-content:center;text-align:center}canvas{display:block;margin:0 auto;cursor:move}</style></div></div></div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/03/08/something-about-crypto/" title="something about crypto"><img src="https://yili979.oss-cn-beijing.aliyuncs.com/img/image-20220124000713258.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="something about crypto"/></a><div class="content"><a class="title" href="/blog/2022/03/08/something-about-crypto/" title="something about crypto">something about crypto</a><time datetime="2022-03-08T12:01:13.000Z" title="发表于 2022-03-08 20:01:13">2022-03-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/03/08/golang%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" title="golang内存管理"><img src="https://yili979.oss-cn-beijing.aliyuncs.com/img/202203081958270.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="golang内存管理"/></a><div class="content"><a class="title" href="/blog/2022/03/08/golang%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" title="golang内存管理">golang内存管理</a><time datetime="2022-03-08T11:55:30.000Z" title="发表于 2022-03-08 19:55:30">2022-03-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/03/08/%E9%89%B4%E6%9D%83%E7%B3%BB%E7%BB%9F/" title="鉴权系统"><img src="https://yili979.oss-cn-beijing.aliyuncs.com/img/202203081950401.jpeg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="鉴权系统"/></a><div class="content"><a class="title" href="/blog/2022/03/08/%E9%89%B4%E6%9D%83%E7%B3%BB%E7%BB%9F/" title="鉴权系统">鉴权系统</a><time datetime="2022-03-08T11:49:53.000Z" title="发表于 2022-03-08 19:49:53">2022-03-08</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            <a class="card-more-btn" href="/blog/categories/" title="查看更多">
    <i class="fas fa-angle-right"></i></a>
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/JVM/"><span class="card-category-list-name">JVM</span><span class="card-category-list-count">3</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/Java-8/"><span class="card-category-list-name">Java 8</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/Java-NIO/"><span class="card-category-list-name">Java NIO</span><span class="card-category-list-count">2</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/MongoDB/"><span class="card-category-list-name">MongoDB</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/Mysql/"><span class="card-category-list-name">Mysql</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/Redis/"><span class="card-category-list-name">Redis</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/SpringBoot/"><span class="card-category-list-name">SpringBoot</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/blog/categories/go/"><span class="card-category-list-name">go</span><span class="card-category-list-count">7</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/blog/tags/IO/" style="font-size: 1.1em; color: #999">IO</a> <a href="/blog/tags/JVM/" style="font-size: 1.37em; color: #99a4b2">JVM</a> <a href="/blog/tags/Java8/" style="font-size: 1.1em; color: #999">Java8</a> <a href="/blog/tags/MongoDB/" style="font-size: 1.1em; color: #999">MongoDB</a> <a href="/blog/tags/Netty/" style="font-size: 1.1em; color: #999">Netty</a> <a href="/blog/tags/Redis/" style="font-size: 1.1em; color: #999">Redis</a> <a href="/blog/tags/SpringBoot/" style="font-size: 1.1em; color: #999">SpringBoot</a> <a href="/blog/tags/crypto/" style="font-size: 1.1em; color: #999">crypto</a> <a href="/blog/tags/go/" style="font-size: 1.5em; color: #99a9bf">go</a> <a href="/blog/tags/golang/" style="font-size: 1.23em; color: #999ea6">golang</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/blog/archives/2022/03/"><span class="card-archive-list-date">三月 2022</span><span class="card-archive-list-count">4</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/blog/archives/2022/01/"><span class="card-archive-list-date">一月 2022</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/blog/archives/2021/10/"><span class="card-archive-list-date">十月 2021</span><span class="card-archive-list-count">22</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">28</div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">48.8k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2022-03-08T12:42:16.474Z"></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By yili</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function subtitleType () {
  if (true) { 
    var typed = new Typed("#subtitle", {
      strings: "我一路向北&#44;离开有你的季节".split(","),
      startDelay: 300,
      typeSpeed: 150,
      loop: false,
      backSpeed: 50
    })
  } else {
    document.getElementById("subtitle").innerHTML = '我一路向北&#44;离开有你的季节'
  }
}

if (true) {
  if (typeof Typed === 'function') {
    subtitleType()
  } else {
    getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
  }
} else {
  subtitleType()
}</script></div><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>